package com.xidian.zhiancloud.controller.myyb;

import com.xidian.zhiancloud.dto.ResultDTO;
import com.xidian.zhiancloud.enums.GeneralResponseEnums;
import com.xidian.zhiancloud.model.SysProcessManagement;
import com.xidian.zhiancloud.service.myyb.IProcessManagementService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 系统设置-流程管理
 */
@RestController
@RequestMapping("/processManagement")
public class ProcessManagementController {

    private final static Logger logger = LoggerFactory.
            getLogger(ProcessManagementController.class);

    @Autowired
    private IProcessManagementService processManagementService;


    /**
     * 流程管理列表
     * @return 返回 ResultDTO 对象
     */
    @GetMapping("/selectProcessManagementList")
    public ResultDTO<List<SysProcessManagement>> selectProcessManagementList() {
        String processManagementStatus = "0";
        Map<String, Object> mapResult = new HashMap<String, Object>();
        mapResult.put("processManagementStatus", processManagementStatus);
//        List<SysProcessManagement> processManagementList = processManagementService.selectProcessManagementList(mapResult);
        return  ResultDTO.successOf(processManagementService.selectProcessManagementList(mapResult),GeneralResponseEnums.SUCCESS);
    }

    /**
     * 删除流程
     * @param id 流程ID
     * @return 返回 ResultDTO 对象
     */
    @GetMapping("/deleteProcessManagement")
    public ResultDTO<SysProcessManagement> deleteProcessManagement(@RequestParam("id") Long id) {
        return ResultDTO.successOf(processManagementService.
           deleteProcessManagement(id),GeneralResponseEnums.SUCCESS);
    }

    /**
     * 编辑流程
     * @param processManagement 编辑流程的数据
     * @return 返回 ResultDTO 对象
     */
    @PatchMapping("/patchById")
    public ResultDTO<Boolean> patchById(SysProcessManagement processManagement) {
        processManagementService.patchById(processManagement);
        return ResultDTO.successOf(GeneralResponseEnums.SUCCESS);
    }

    /**
     * 添加流程
     * @param processManagement 添加流程的数据
     * @return 返回 ResultDTO 对象
     */
    @PostMapping("/add")
    public ResultDTO<Boolean> add(SysProcessManagement processManagement) {
        processManagementService.add(processManagement);
        return ResultDTO.successOf(GeneralResponseEnums.SUCCESS);
    }

    /**
     * 查看流程详情
     * @param id 流程ID
     * @return 返回 ResultDTO 对象
     */
    @GetMapping("/getById")
    public ResultDTO<SysProcessManagement> getById(@RequestParam("id") Long id) {
        return ResultDTO.successOf(processManagementService.getById(id),
                GeneralResponseEnums.SUCCESS);
    }

}
